# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'editCategory.ui'
#
# Created: Fri Jun 01 01:14:48 2012
#      by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
import pyodbc

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Form(QtGui.QDialog):
    
    def save(self):
        '''
        zapisuje zmiany
        '''
        conn = pyodbc.connect(self.databaseDir)
        cur = conn.cursor()
        cur.execute("UPDATE Measures SET name=? WHERE name=?",str(self.lineEdit.text()),str(self.measure.name))
        conn.commit()
        conn.close()
        self.MeasureManagment.getAllMeasures()
        self.close()
        
    
    def cancel(self):
        self.close()
        
    def setupUi(self, Form,measure,MeasureManagment,databaseDir):

        '''jednostka na ktorej pracujemy'''
        self.measure = measure
        '''poprzedni wigdet'''
        self.MeasureManagment = MeasureManagment
        self.databaseDir = databaseDir
        
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(358, 132)
        Form.setGeometry(QtCore.QRect(50,50,100,100))
        
        self.lineEdit = QtGui.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(20, 40, 311, 20))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.nameLabel = QtGui.QLabel(Form)
        self.nameLabel.setGeometry(QtCore.QRect(20, 20, 46, 13))
        self.nameLabel.setObjectName(_fromUtf8("nameLabel"))
        self.saveButton = QtGui.QPushButton(Form)
        self.saveButton.setGeometry(QtCore.QRect(180, 90, 75, 23))
        self.saveButton.setObjectName(_fromUtf8("saveButton"))
        self.saveButton.connect(self.saveButton, QtCore.SIGNAL("clicked()"),self.save)
        
        self.cancelButton = QtGui.QPushButton(Form)
        self.cancelButton.setGeometry(QtCore.QRect(260, 90, 75, 23))
        self.cancelButton.setObjectName(_fromUtf8("cancelButton"))
        self.cancelButton.connect(self.cancelButton, QtCore.SIGNAL("clicked()"),self.cancel)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.nameLabel.setText(QtGui.QApplication.translate("Form", "Nazwa:", None, QtGui.QApplication.UnicodeUTF8))
        self.saveButton.setText(QtGui.QApplication.translate("Form", "Zapisz", None, QtGui.QApplication.UnicodeUTF8))
        self.cancelButton.setText(QtGui.QApplication.translate("Form", "Anuluj", None, QtGui.QApplication.UnicodeUTF8))

